<script src="<?php echo ThemePath(); ?>/js/bootbox.js" type="text/javascript"></script>
<script>
    jQuery(document).ready(function() {
        window.blinker = setInterval(function() {
            if (window.blink) {
                $('.blink').css('color', 'red');
                window.blink = false;
            } else {
                $('.blink').css('color', 'white');
                window.blink = true;
            }
        }, 200);
    });
</script>
<section>
    <div class="container">
        <div class="row">
            <div class="span12">	            	
                <ul class="breadcrumb">
                    <li class="previous"><a href="#">Home /</a></li>                
                    <li class="disable"><a href="#">My Queries</a></li>
                </ul>  
                <div class="common">
                    <div class="whiteBg greenBor padding20px">
                        <h5 class="fnt-size20 txtgreen">All Queries</h5>
                    </div>
                </div> 
                <div class="common sortingDiv">                
                    <fieldset>
                        <div class="col">
                            <p class="sorttxt inline-block">Filter By</p>
                        </div>            
                        <div class="col">   
                            <select class="selectsort" id="sort_class_course" name="sort_class_course">
                                <option value="">Select</option>
                                <option value="1">Classes</option>
                                <option value="2">Courses</option>
                            </select>
                        </div>
                        <div class="col">
                            <select class="selectsort" id="sort_location" name="sort_location">
                                <option value="">Select</option>
                                <option value="1">Delhi</option>
                            </select>
                        </div>
                        <div class="col">
                            <select class="selectsort" id="sort_respond_unrespond" name="sort_respond_unrespond">
                                <option value="">Select</option>
                                <option value="1">Responded</option>
                                <option value="2">Unresponded</option>
                            </select>
                        </div>
                        <div class="col">
                            <select class="selectsort" id="sort_converted_unconverted" name="sort_converted_unconverted">
                                <option value="">Select</option>
                                <option value="1">Converted</option>
                                <option value="2">Unconverted</option>
                            </select>
                        </div>
                    </fieldset>
                    <div class="clear"></div>
                </div>



                <div class="viewTable addmarginB20">
                    <div class="detail scroll-item">
                        <div class="rowG th" style="width:1090px;">
                            <div class="col col2">
                                <div class="padding">
                                    <h5>Sr. No</h5>
                                </div>
                            </div>
                            <div class="col col4">
                                <div class="padding">
                                    <h5>Name</h5>
                                </div>
                            </div>
                            <div class="col col4">
                                <div class="padding">
                                    <h5>Class / Course Name</h5>
                                </div>
                            </div>
                            <div class="col col3">
                                <div class="padding">
                                    <h5>Query Date</h5>
                                </div>
                            </div>
                            <div class="col col3">
                                <div class="padding">
                                    <h5>Time since query</h5>
                                </div>
                            </div>
                            <div class="last collast">
                                <div class="padding">
                                    <h5>Respond/Unrespond</h5>
                                </div>
                            </div>

                        </div>
                        <?php
                        $this->widget('zii.widgets.CListView', array(
                            'dataProvider' => $dataProvider,
                            'afterAjaxUpdate' => 'reinstallCheckBox',
                            'itemView' => '_view',
                            'id' => 'ajaxListView',
                            'summaryText' => '',
                        ));
                        Yii::app()->clientScript->registerScript('reinstallCheckBox', "
                    function reinstallCheckBox(id, data) {   
                       $('.conver_class').fancyfields({
				onCheckboxChange: function (input, isChecked) {
					 updateConvert(input.attr('value'), isChecked,input.attr('id'));
			   }
		  });
                }
                    ");
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<div  class="addmarginB30"></div>
<?php
$allClassCourseInfo = array();
$classDetails = literalEndingTommorow('', '', '');
$courseDetails = runningCurrentCoursesByUser('', '', ''); //Null parameter means these value $profiles, $userType, $getValue)
$allClassCourseInfo = array_merge($classDetails, $courseDetails);
usort($allClassCourseInfo, 'date_compare');
$validatedata = literalendingtommorowValiadte($allClassCourseInfo);
if (!empty($validatedata)) {
    $this->renderPartial('/classes/literallyEndingtomorrow', array('allClassCourseInfo' => $allClassCourseInfo));
}
?>
<?php
Yii::app()->clientScript->registerScript('search', "var ajaxUpdateTimeout;
    var ajaxRequest;
    $('.selectsort').fancyfields({
	onSelectChange: function() {
	var classCourseval=$('#sort_class_course').val();
	var sort_locationval=$('#sort_location').val();
	var sort_respond_unrespond=$('#sort_respond_unrespond').val();
	var sort_converted_unconverted=$('#sort_converted_unconverted').val();
        ajaxRequest = 'class_course='+classCourseval+'&location=' + sort_locationval+'&respond_unrespond=' + sort_respond_unrespond+'&converted_unconverted=' + sort_converted_unconverted;
        clearTimeout(ajaxUpdateTimeout);
        ajaxUpdateTimeout = setTimeout(function () {
            $.fn.yiiListView.update(
                'ajaxListView',
                {data: ajaxRequest}
            )
        },
        300);}
    });"
)
?>
<script type="text/javascript" src="<?php echo ThemePath(); ?>/js/jquery.nicescroll.js"></script>
<script>
    $(".scroll-item").niceScroll();
</script>
<script type="text/javascript">
    function showQuery(id) {
        $(".sendMessageTouserOpenBox").hide();
        $("#" + id).toggle('slow').show();
    }

    function hideQuery(id) {
        $(".sendMessageTouserOpenBox").hide();
        $("#" + id).toggle('slow').hide();
    }



    jQuery(document).ready(function() {
        $(".conver_class").fancyfields({
            onCheckboxChange: function(input, isChecked) {
                updateConvert(input.attr("value"), isChecked, input.attr("id"));
            }
        });
        $("#queryBox").niceScroll({touchbehavior: true, autohidemode: true});
    });

    function updateConvert(queryId, checked, id) {
        bootbox.confirm("Are you sure want to make converted user?", function(result) {
            if (result != false) {
                jQuery.ajax({
                    'type': 'POST',
                    'url': "<?php echo Yii::app()->createAbsoluteUrl("MakeQuery/UpdateConvert"); ?>",
                    data: 'MakeQuery[id]=' + queryId + '&checked=' + checked,
                    'success': function(data) {
                        if (data == "success") {
                            $('#' + id).fancyfields("disable");
                        }
                    },
                    'cache': false});
            }

        });

    }

    function sendAMailToAllConvertedUser(id, classid, userid,classcoursetyp) {
        var subject = $("#subject_" + id).val();
        var msgval = $("#message_text_" + id).val();
        if (subject == '') {
            $("#errorMessage_subject_" + id).text('Subject can not blank.');
            return false;
        }
        if (msgval == '') {
            $("#errorMessage_subject_" + id).text('');
            $("#errorMessage_msg_" + id).text('Message  can not blank.')
            return false;
        }
        if (subject != '' && msgval != '') {
            jQuery.ajax({
                'type': 'POST',
                'url': "<?php echo Yii::app()->createAbsoluteUrl("MailConversation/sendMailTouser"); ?>",
                'data': "selectedUser=" + userid + "&subject=" + subject + "&msgval=" + msgval + "&classId=" + classid + "&makeQueryId=" + id + "&type=" + classcoursetyp,
                'beforeSend': function(jqXHR, settings) {
                    $("#AjaxLoader_" + id).show();
                },
                'success': function(data) {
                    $("#AjaxLoader_" + id).hide();
                    if($.trim(data)=='success') {
                        $("#send_a_msg_box_" + id).hide();
                        $("#convertedUser_" + id).show();
                        $("#respond_" + id).show();
                        $("#unrespond_" + id).hide();
                        $("#formResult_" + id).html("Mail Send Successfully .");
                    }
                },
                'cache': false
            });
        }

    }


</script>

